package com.lemon.equipment.controller;

import com.lemon.equipment.domain.vo.ResultVO;
import com.lemon.equipment.service.FileUploadService;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @Author Lemon-boy
 * @Date 2024/8/12
 */

@RequestMapping("/file")
@Controller
public class FileController {

    @Resource
    private FileUploadService fileUploadService;

    @PostMapping(value = "/upload" , consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public ResultVO<Long> upload(@RequestPart MultipartFile file){
        Long fileId = fileUploadService.upload(file);
        return ResultVO.success(fileId);
    }

    @GetMapping("/download/{fileId}")
    public void download(@PathVariable Long fileId , HttpServletResponse response){
        fileUploadService.download(fileId,response);
    }
}
